package com.yzi.utilitys
{
	import flash.text.Font;

	public class FontUtility
	{
		public function FontUtility()
		{
			throw new Error("Static Class.");
		}
		
		static public function GetDefaultEmbedFontName(): String
		{
			var result:String = "";
			var koreanSupportFontList:Vector.<String> = GetKoreanSupportEmbedFontNameList();
			if(koreanSupportFontList.length > 0) result = koreanSupportFontList[0];
			
			if(result == "") {
				var fontList:Array = Font.enumerateFonts(true);
				result = fontList[0];
			}
			
			return result;
		}
		
		static public function GetKoreanSupportEmbedFontNameList(): Vector.<String>
		{
			var result:Vector.<String> = new Vector.<String>();
			var fontList:Array = Font.enumerateFonts(true);
			
			for each(var font:Font in fontList)
			{
				if(IsKoreanSupport(font.fontName) == true) {
					result.push(font.fontName);
				}
			}
			
			return result;
		}
		
		static public function GetFontByFontName($fontName:String): Font
		{
			var result:Font;
			var fontList:Array = Font.enumerateFonts(true);
			for each(var font:Font in fontList)
			{
				if(font.fontName == $fontName) {
					result = font;
					break;
				}
			}
			
			return result;
		}
		
		static public function IsExistFont($fontName:String): Boolean
		{
			var result:Boolean = false;
			var fontList:Array = Font.enumerateFonts(true);
			for each(var font:Font in fontList)
			{
				if(font.fontName == $fontName) {
					result = true;
					break;
				}
			}
			
			return result;
		}
		
		static public function IsKoreanSupport($fontName:String): Boolean { return IsSupportGlyphs($fontName, "가"); }
		
		static public function IsSupportGlyphs($fontName:String, $string:String): Boolean
		{
			var result:Boolean = false;
			var font:Font = GetFontByFontName($fontName);
			if(font != null) result = font.hasGlyphs($string);
			
			return result;
		}
	}
}